
const song = {
    state: {    //存储的字段
        listOfSongs: [],     //当前歌曲列表
        isPlay: false,   //是否播放中
        url: '',     //歌曲地址
        id: '',   //歌曲id
        playButtonUrl: '#icon-bofang',  //播放状态的图标
        duration: 0,    //音乐时长
        curTime: 0,     //当前音乐的播放位置
        changeTime: 0,  //指定播放时刻
        title: '',      //歌名
        artist: '',     //歌手名
        picUrl: '',     //歌曲图片
        autoNext: true, //用于自动触发播放下一首
        lyric: [],      //未处理的歌词数据
        tempList: {},   //单个歌单信息或歌手信息
        listIndex: null, //当前歌曲在歌单中的位置
        volume: 50      //音量
    },
    getters: {  //getter方法
        listOfSongs: state => {
            let listOfSongs = state.listOfSongs
            if (!listOfSongs.length) {
                //listOfSongs = JSON.parse(window.sessionStorage.getItem('listOfSongs') || null)
                return [];
            }
            return listOfSongs;
            //return [{"id":4,"singerId":44,"name":"60号-《傻屌之歌》","introduction":"《奥利给》","createTime":"2021-06-10 09:54:30","updateTime":"2021-06-10 19:52:11","pic":"/img/songPic/16233259310752.jpg","lyric":"[00:00.000] 作曲 : 陈小霞\r\n[00:16.08]如果那两个字没有颤抖\r\n[00:20.06]我不会发现 我难受\r\n[00:23.22]怎么说出口\r\n[00:27.00]也不过是分手\r\n[00:31.54]如果对于明天没有要求\r\n[00:35.63]牵牵手就像旅游\r\n[00:38.54]成千上万个门口\r\n[00:42.43]总有一个人要先走\r\n[00:48.20]怀抱既然不能逗留\r\n[00:51.58]何不在离开的时候\r\n[00:54.51]一边享受 一边泪流\r\n[01:01.58]十年之前\r\n[01:03.54]我不认识你 你不属于我\r\n[01:07.33]我们还是一样\r\n[01:10.12]陪在一个陌生人左右\r\n[01:13.54]走过渐渐熟悉的街头\r\n[01:17.33]十年之后\r\n[01:19.11]我们是朋友 还可以问候\r\n[01:23.00]只是那种温柔\r\n[01:25.48]再也找不到拥抱的理由\r\n[01:29.27]情人最后难免沦为朋友\r\n[01:57.51]怀抱既然不能逗留\r\n[02:01.37]何不在离开的时候\r\n[02:04.28]一边享受 一边泪流\r\n[02:11.36]十年之前\r\n[02:13.18]我不认识你 你不属于我\r\n[02:16.98]我们还是一样\r\n[02:19.65]陪在一个陌生人左右\r\n[02:23.47]走过渐渐熟悉的街头\r\n[02:26.91]十年之后\r\n[02:28.79]我们是朋友 还可以问候\r\n[02:32.56]只是那种温柔\r\n[02:35.04]再也找不到拥抱的理由\r\n[02:38.83]情人最后难免沦为朋友\r\n[02:48.70]直到和你做了多年朋友\r\n[02:52.74]才明白我的眼泪\r\n[02:55.86]不是为你而流\r\n[02:59.90]也为别人而流","url":"/song/16232900709001.jpg"},{"id":8,"singerId":44,"name":"60号-《枕边童话》","introduction":"《奥利给》","createTime":"2021-06-10 16:06:03","updateTime":"2021-06-10 16:06:03","pic":"/img/songPic/tubiao.jpg","lyric":"[00:00.000] 作词 : 唐思淼\r\n[00:01.000] 作曲 : 爱写歌的小田\r\n[00:02.000] 监制 : 张鹏闻\r\n[00:03.000] 出品 : 飞行计划\r\n[00:04.000] 宣发统筹 : 小小晞\r\n[00:05.000] 发行 : 讯飞音乐\r\n[00:06.000] 未经著作权人书面许可，不得以任何方式（包括翻唱、翻录等）使用\r\n[00:11.85]枕头下的童话书\r\n[00:14.57]私自收藏的幸福\r\n[00:17.04]少年的我想倾诉什么感触\r\n[00:22.34]迷失森林的小鹿\r\n[00:25.05]会不会遇到女巫\r\n[00:27.73]故事拉开序幕\r\n[00:32.07]星光拨开最神秘的雾\r\n[00:34.78]踮起脚尖旋转舞步\r\n[00:37.48]恍恍惚惚听谁在哭\r\n[00:42.24]月光叮嘱窗外的植物\r\n[00:45.23]遇到孩子记得让路\r\n[00:48.56]谁会救赎我孤独\r\n[00:52.51]你是那童话里的公主站在光明处\r\n[00:57.55]我戴上华丽假面转身躲进黑礼服\r\n[01:02.68]请和我起舞趁着童话还没有结束\r\n[01:07.86]天亮后让一切 恢复\r\n[01:33.99]枕头下的童话书\r\n[01:36.54]私自收藏的幸福\r\n[01:39.07]少年的我想倾诉什么感触\r\n[01:44.21]迷失森林的小鹿\r\n[01:46.85]会不会遇到女巫\r\n[01:49.69]故事拉开序幕\r\n[01:54.27]星光拨开最神秘的雾\r\n[01:57.09]踮起脚尖旋转舞步\r\n[01:59.62]恍恍惚惚听谁在哭\r\n[02:04.49]月光叮嘱窗外的植物\r\n[02:07.53]遇到孩子记得让路\r\n[02:10.16]谁会救赎我孤独\r\n[02:15.02]你是那童话里的公主站在光明处\r\n[02:19.98]我戴上华丽假面转身躲进黑礼服\r\n[02:25.05]请和我起舞趁着童话还没有结束\r\n[02:30.21]天亮后让一切 恢复\r\n[02:35.54]你是那童话里的公主站在光明处\r\n[02:40.21]我戴上华丽假面转身躲进黑礼服\r\n[02:45.44]请和我起舞趁着童话还没有结束\r\n[02:50.64]天亮后让一切 恢复","url":"/song/1623312362586枕边通话.mp3"}];
        },
        isPlay: state => state.isPlay,
        url: state => state.url,
        id: state => state.id,
        playButtonUrl: state => state.playButtonUrl,
        duration: state => {
            let duration = state.duration;
            if(!duration){
                duration = JSON.parse(window.sessionStorage.getItem('duration') || null)
            }
            return duration;
        },
        curTime: state => {
            let curTime = state.curTime;
            if(!curTime){
                curTime = JSON.parse(window.sessionStorage.getItem('curTime') || null)
            }
            return curTime;
        },
        changeTime: state => {
            let changeTime = state.changeTime;
            if(!changeTime){
                changeTime = JSON.parse(window.sessionStorage.getItem('changeTime') || null)
            }
            return changeTime;
        },
        title: state => {
            let title = state.title;
            if(!title){
                title = JSON.parse(window.sessionStorage.getItem('title') || null)
            }
            return title;
        },
        artist: state => {
            let artist = state.artist;
            if(!artist){
                artist = JSON.parse(window.sessionStorage.getItem('artist') || null)
            }
            return artist;
        },
        picUrl: state => {
            let picUrl = state.picUrl;
            if(!picUrl){
                picUrl = JSON.parse(window.sessionStorage.getItem('picUrl') || null)
            }
            return picUrl;
        },
        autoNext: state => {
            let autoNext = state.autoNext;
            if(!autoNext){
                autoNext = JSON.parse(window.sessionStorage.getItem('autoNext') || null)
            }
            return autoNext;
        },
        lyric: state => {
            let lyric = state.lyric;
            if(!lyric){
                lyric = JSON.parse(window.sessionStorage.getItem('lyric') || null)
            }
            return lyric;
        },
        tempList: state => {
            let tempList = state.tempList;
            if(!tempList){
                tempList = JSON.parse(window.sessionStorage.getItem('tempList') || null)
            }
            return tempList;
        },
        listIndex: state => {
            let listIndex = state.listIndex;
            if(!listIndex){
                listIndex = JSON.parse(window.sessionStorage.getItem('listIndex') || null)
            }
            return listIndex;
        },
        volume: state => {
            let volume = state.volume;
            if(!volume){
                volume = JSON.parse(window.sessionStorage.getItem('volume') || null)
            }
            return volume;
        }
    },
    mutations: {    //setter方法
        setListOfSongs: (state, listOfSongs) => {
            console.log("set");
            state.listOfSongs = listOfSongs
            //window.sessionStorage.setItem('listOfSongs', JSON.stringify(listOfSongs))
        },
        setIsPlay: (state, isPlay) => {state.isPlay = isPlay},
        setUrl: (state, url) => (state.url = url),
        setId: (state, id) => {state.id = id},
        setPlayButtonUrl: (state, playButtonUrl) => {state.playButtonUrl = playButtonUrl},
        setDuration: (state, duration) => {
            state.duration = duration;
            window.sessionStorage.setItem('duration', JSON.stringify(duration));
        },
        setCurTime: (state, curTime) => {
            state.curTime = curTime;
            window.sessionStorage.setItem('curTime', JSON.stringify(curTime));
        },
        setChangeTime: (state, changeTime) => {
            state.changeTime = changeTime;
            window.sessionStorage.setItem('changeTime', JSON.stringify(changeTime));
        },
        setTitle: (state, title) => {
            state.title = title;
            window.sessionStorage.setItem('title', JSON.stringify(title));
        },
        setArtist: (state, artist) => {
            state.artist = artist;
            window.sessionStorage.setItem('artist', JSON.stringify(artist));
        },
        setPicUrl: (state, picUrl) => {
            state.picUrl = picUrl;
            window.sessionStorage.setItem('picUrl', JSON.stringify(picUrl));
        },
        setAutoNext: (state, autoNext) => {
            state.autoNext = autoNext;
            window.sessionStorage.setItem('autoNext', JSON.stringify(autoNext));
        },
        setLyric: (state, lyric) => {
            state.lyric = lyric;
            window.sessionStorage.setItem('lyric', JSON.stringify(lyric));
        },
        setTempList: (state, tempList) => {
            state.tempList = tempList;
            window.sessionStorage.setItem('tempList', JSON.stringify(tempList));
        },
        setListIndex: (state, listIndex) => {
            state.listIndex = listIndex;
            window.sessionStorage.setItem('listIndex', JSON.stringify(listIndex));
        },
        setVolume: (state, volume) => {
            state.volume = volume;
            window.sessionStorage.setItem('volume', JSON.stringify(volume));
        }
    }
};
export default song;